/**
 * 
 */
package neptune.web.client.callback;

import neptune.web.client.WebInterface;
import neptune.web.client.commands.OpenExperimentViewCommand;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.PopupPanel;

/**
 * @author oltremago
 * 
 */
public class ExperimentDeploymentCallback implements AsyncCallback<String> {

	private PopupPanel popup;
	private String expName;

	public ExperimentDeploymentCallback(PopupPanel popup, String expName) {
		super();
		this.popup = popup;
		this.expName = expName;
	}

	public void onSuccess(String result) {
		if (popup != null)
			popup.hide();
		String message = "Experiment '" + expName + "' successfully deployed.";
		WebInterface.addMessageToConsoleAndShowDialog(message, false);
		new OpenExperimentViewCommand(expName).execute();
	}

	public void onFailure(Throwable caught) {
		if (popup != null)
			popup.hide();
		String message = "Error while starting experiment '" + expName + "':\n"
				+ caught.getMessage();
		WebInterface.addMessageToConsoleAndShowDialog(message, true);
		new OpenExperimentViewCommand(expName).execute();
	}
}
